package service.impl;

import java.util.List;

import org.hibernate.Transaction;
import org.hibernate.classic.Session;

import pojo.Alarm;
import pojo.Car;
import pojo.Distance;
import pojo.PageBean;
import pojo.User;
import service.UserService;
import dao.UserDao;
import daoImpl.UserDaoImpl;



public class UserServiceImpl implements UserService {
	private UserDao userDao = new UserDaoImpl();
	

	public UserDao getUserDao() {
		return userDao;
	}


	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}




	@Override
	public User login(User user) {
		return userDao.login(user);
	
	}


	@Override
	public boolean register(User user) {

		String username = user.getUsername();
		if(userDao.queryByUsername(username)!=null){//如果不为空，说明用户名已经存在
			return false;
		}else{
			//保存新注册的用户
			userDao.save(user);
			return true;
		}
	
	}

	//绑定车
	@Override
	public boolean bind(Car car) {

		String username = car.getUsername();
		if(username==null || "".equals(username.trim())){
			return false;
		}
		if(userDao.query(username)!=null){
			return false;
		}else{
			//绑定智能手表
			 car = userDao.bind(car);
			 if(car==null){
				 return false;
				 
			 }else{
				 return true;
			 }
		}
	}


	/* 解除绑定
	 * @see service.UserService#dele(pojo.Watchuser)
	 */
	@Override
	public boolean dele(String username) {
		//String username = watchuser.getUsername();
		if(username==null){
			return false;
		}
		if(userDao.query(username)==null){
			return false;
		}else{
			userDao.dele(username);
			return true;
		}
		
	}


	/* 
	 * @see service.UserService#queryList(java.lang.String)
	 */
	@Override
	public List<User> queryList(String binder) {
		return  userDao.queryList(binder);
	}


	/* (non-Javadoc)
	 * @see service.UserService#queryCarList(java.lang.String)
	 */
	@Override
	public List<Car> queryCarList(String binder) {
		return userDao.queryCarList(binder);
	
	}


	/* 
	 * @see service.UserService#update(pojo.Car)
	 */
	@Override
	public Car update(Car car) {
		if(car==null){
			return null;
		}
		return userDao.update(car);

	}


	/* 
	 * @see service.UserService#queryAllAlarm(pojo.Alarm)
	 */
	@Override
	public List<Alarm> queryAllAlarm(String username) {
	
		return userDao.queryAllAlarm(username);
	}



	/* 
	 * @see service.UserService#queryDistance(pojo.Distance)
	 */
	@Override
	public List<Distance> queryDistance(String entity_name,int year,int mon) {
		return userDao.queryDistance(entity_name, year, mon);
	}


	/* 
	 * @see service.UserService#getAlarmList(java.lang.String, java.lang.String)
	 */
	@Override
	public List getAlarmList(String page, String rows) throws Exception {
		return userDao.getAlarmList(page, rows);
	}


	/* 
	 * @see service.UserService#getAlarmTotal()
	 */
	@Override
	public int getAlarmTotal() throws Exception {
		return userDao.getAlarmTotal();
	}


	



}
